package org.liuqm.mapper;

import org.liuqm.CustoParam;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Iterator;
import java.util.Map;

public class RequestUtils {


    public static void getCount(Map map) throws InvocationTargetException, IllegalAccessException {
        BuyerMapper buyerMapper = new BuyerMapperImpl();


        Class clazz = buyerMapper.getClass();
        Method[] methods = clazz.getDeclaredMethods();
        clazz.getAnnotation(CustoParam.class);

        for (int i = 0; i < methods.length; i++) {
            Method method = methods[i];
            String[] values = new String[method.getParameters().length];
            Parameter[]parameters = method.getParameters();
            for (int j = 0; j < parameters.length; j++) {
                //通过解析注解获得参数名称
                CustoParam annotation = parameters[j].getAnnotation(CustoParam.class);
                String paramName=annotation.value();
                values[j] = (String) map.get(paramName);
            }
            method.invoke(buyerMapper, values);
        }


    }
}
